import {getSearch} from "../../api/search"
// pages/search/search.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        test:'',
        lists:null,
        searchData:["小米","电视","冰箱","空调","充电宝"]
    },
    // 点击推荐文字进入
    goSearch(event){
        console.log(event.target.dataset.name);
        let test = event.target.dataset.name;
        wx.setStorageSync('name', test);
        wx.setStorageSync('query', test);
        wx.navigateTo({
          url: '/pages/brandmenu/brandmenu',
        })
    },
    // 键盘输入时触发
    searching(event){
        console.log(event.detail.value);
        let test = event.detail.value;
        this.setData({
            test:test
        })
        getSearch({query:test}).then(data=>{
            console.log(data);
            this.setData({
                lists:data.message
            })
        })
    },
    // 回车时候触发
    goBrandMenu(event){
        console.log("回车时候触发");
        let test = event.detail.value;
        wx.setStorageSync('name', test);
        wx.setStorageSync('query', test);
        wx.navigateTo({
          url: '/pages/brandmenu/brandmenu',
        })
    },
    gocar(){
        console.log(this.data.test);
        let test = this.data.test;
        wx.setStorageSync('name', test);
        wx.setStorageSync('query', test);
        wx.navigateTo({
          url: '/pages/brandmenu/brandmenu',
        })  
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
       
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})